import  pandas as pd
import  json
import tos
import  time
import uuid
import mysql.connector
import logging
from bytehouse_driver import Client
import  numpy as np
import json
# Access key 和 Secret key 可在用户火山引擎账号中查找
ak = "AKLTMmFmMzVmNmY5ZDEyNDNmNWEyZTU2MDM3Y2EzMDJlZTk"
sk = "WVdNeFpXRXdNekV4Tm1ZME5EZGxPRGc0TUdFNE1HWXdNV1ZqTkdNNU9HRQ=="
# your endpoint 和 your region 填写Bucket 所在区域对应的Endpoint。# 以华北2(北京)为例，your endpoint 填写 tos-cn-beijing.volces.com，your region 填写 cn-beijing。
endpoint = "tos-cn-beijing.ivolces.com"
region = "cn-beijing"

def get_binary_with_16(SuppressReason):
    # 设定希望的二进制长度
    desired_length = 16
    # 获取二进制表示的位数
    num_bits = SuppressReason.bit_length()
    # 动态调整长度并获取二进制表示
    binary_representation = convert_to_binary_with_length(SuppressReason, max(num_bits, desired_length))
    return binary_representation
def get_binary_with_27(SuppressReason):
    # 设定希望的二进制长度
    desired_length = 27
    # 获取二进制表示的位数
    num_bits = SuppressReason.bit_length()
    # 动态调整长度并获取二进制表示
    binary_representation = convert_to_binary_with_length(SuppressReason, max(num_bits, desired_length))
    return binary_representation
def get_dict(vechicle_id,start_time_str,bagid,path,scid_dict,level1,level2,level3):
    dict = {}
    dict["vehicle_id"] = vechicle_id
    dict["start_time_str"] = start_time_str
    dict["scid"] = bagid
    dict["path"] = path
    dict["level1"] = level1
    dict["level2"] = level2
    dict["level3"] = level3
    day = start_time_str[0:4] + start_time_str[5:7] + start_time_str[8:10]
    month = start_time_str[0:4] + start_time_str[5:7]
    dict["day"] = day
    dict["month"] = month
    dict["scid_start_time_str"] = scid_dict["scid_start_time_str"]
    dict["icu2_odometer"] = scid_dict["ICU2_Odometer"]
    dict["idb3_vehiclespd"] = scid_dict["IDB3_VehicleSpd"]
    dict["acu2_longaccsensorvalue"] = scid_dict["ACU2_LongAccSensorValue"]
    dict["acu2_lataccsensorvalue"] = scid_dict["ACU2_LatAccSensorValue"]
    dict["acu2_vehicledynyawrate"] = scid_dict["ACU2_VehicleDynYawRate"]
    dict["eps1_steeranglespd"] = scid_dict["EPS1_SteerAngleSpd"]
    dict["lane_curvature"] = scid_dict["lane_curvature"]
    dict["eps1_torsionbartorque"] = scid_dict["EPS1_TorsionBarTorque"]
    dict["cs1_gearpositionreqst"] = scid_dict["CS1_GearPositionReqSt"]
    dict["lane_curvature"] = scid_dict["lane_curvature"]

    uid_string = vechicle_id + start_time_str + bagid + level1 + level2 + level3
    uid = str(uuid.uuid3(uuid.NAMESPACE_DNS, uid_string))
    dict["uid"] = uid
    return dict
def get_dict_list(dict):
    data_list=[]
    data_list.append(dict['vehicle_id'])
    data_list.append(dict['start_time_str'])
    data_list.append(dict['scid'])
    data_list.append(dict['path'])
    data_list.append(dict['level1'])
    data_list.append(dict['level2'])
    data_list.append(dict['level3'])
    data_list.append(dict['day'])
    data_list.append(dict['month'])
    data_list.append(dict["scid_start_time_str"])
    data_list.append(dict['icu2_odometer'])
    data_list.append(dict['idb3_vehiclespd'])
    data_list.append(dict['acu2_longaccsensorvalue'])
    data_list.append(dict['acu2_lataccsensorvalue'])
    data_list.append(dict['acu2_vehicledynyawrate'])
    data_list.append(dict['eps1_steeranglespd'])
    data_list.append(dict['lane_curvature'])
    data_list.append(dict['eps1_torsionbartorque'])
    data_list.append(dict['cs1_gearpositionreqst'])
    data_list.append(dict['uid'])
    data_list.append(dict['day'])
    return data_list
def add_to_bytehouse(dict_list):

    print(dict_list)
    HOST="bytehouse-cn-beijing.volces.com"
    PORT="19000"
    API_KEY="q2p9nLj7tq:TKOCmgrMKp"
    # 配置数据库连接信息
    DATABASE="dwd"
    client = Client.from_url('bytehouse://{}:{}/?user=bytehouse&password={}&database={}&secure=true'.format(HOST, PORT, API_KEY, DATABASE))
    client.execute("INSERT INTO dwd.dwd_trigger_sc_ep40_tda4_v5 VALUES", dict_list)
def get_can_20ms_list(df_can_20ms_list,nsecs,start_time):
    subset_list = [item for item in df_can_20ms_list if item[0] == start_time]
    if not subset_list:
        # 处理找不到匹配start_time的情况
        return None
    # 找到最接近目标值的行数据
    closest_data = min(subset_list, key=lambda x: abs(x[2] - nsecs))

    # 获取最接近值的索引
    index = df_can_20ms_list.index(closest_data)

    # 打印结果
    return  closest_data,index
def get_ttc(df_can_20ms_list,df_can_100ms_source_list,found_nsecs,vechicle_id,bagid,scid_dict,dict_list,start_time):
    list_20ms_data, index_20ms = get_can_20ms_list(df_can_20ms_list, found_nsecs,start_time)
    df_can_100ms_list,index_100ms=get_can_100ms_list(df_can_100ms_source_list, found_nsecs,start_time)
    if (df_can_100ms_list is not None and len(df_can_100ms_list) > 0) and \
       (list_20ms_data is not None and len(list_20ms_data) > 0):
        VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID = list_20ms_data[2]
        EnvmGenObjectList_aObject_0_Kinematic_fDistX = list_20ms_data[5]
        EnvmGenObjectList_aObject_0_Kinematic_fVabsX = list_20ms_data[7]
        EnvmGenObjectList_aObject_1_Kinematic_fDistX = list_20ms_data[11]
        EnvmGenObjectList_aObject_1_Kinematic_fVabsX = list_20ms_data[13]
        EnvmGenObjectList_aObject_2_Kinematic_fDistX = list_20ms_data[17]
        EnvmGenObjectList_aObject_2_Kinematic_fVabsX = list_20ms_data[19]
        EnvmGenObjectList_aObject_3_Kinematic_fDistX = list_20ms_data[23]
        EnvmGenObjectList_aObject_3_Kinematic_fVabsX = list_20ms_data[25]
        EnvmGenObjectList_aObject_4_Kinematic_fDistX = list_20ms_data[29]
        EnvmGenObjectList_aObject_4_Kinematic_fVabsX = list_20ms_data[31]
        EnvmGenObjectList_aObject_5_Kinematic_fDistX = list_20ms_data[35]
        EnvmGenObjectList_aObject_5_Kinematic_fVabsX = list_20ms_data[37]

        start_time_str = df_can_100ms_list[0]
        path = df_can_100ms_list[6]
        IDB3_VehicleSpd = df_can_100ms_list[10]
        AccDisplayObj_CONTROL_ACCEL = df_can_100ms_list[18]
        if VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID == 0:
            ttc = EnvmGenObjectList_aObject_0_Kinematic_fDistX / (
                    EnvmGenObjectList_aObject_0_Kinematic_fVabsX - IDB3_VehicleSpd / 3.6)
            IDB3_VehicleSpd_flag = IDB3_VehicleSpd / 3.6
            if (IDB3_VehicleSpd_flag <= 1 and ttc < 0.8) or (
                    IDB3_VehicleSpd_flag <= 3 and (ttc < 0.25 * IDB3_VehicleSpd_flag + 0.55)) or \
                    (IDB3_VehicleSpd_flag > 3 and IDB3_VehicleSpd_flag <= 10 and (
                            ttc < 0.1 * IDB3_VehicleSpd_flag + 1)) or \
                    (IDB3_VehicleSpd_flag > 10 and ttc < 2):
                level1 = "NNP退出"
                level2 = "触发时刻"
                level3 = "与高亮目标ttc过小"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)

            gap = EnvmGenObjectList_aObject_0_Kinematic_fDistX / (IDB3_VehicleSpd / 3.6)
            if (IDB3_VehicleSpd_flag <= 1 and gap < 1) or (
                    IDB3_VehicleSpd_flag <= 10 and gap < -0.092857143 * IDB3_VehicleSpd_flag + 1.278571429) or \
                    (
                            IDB3_VehicleSpd_flag > 10 and IDB3_VehicleSpd_flag <= 30 and gap < -0.0085 * IDB3_VehicleSpd_flag + 0.435):
                level1 = "NNP退出"
                level2 = "触发时刻"
                level3 = "与高亮目标time_gap过小"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)
        elif VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID == 1:
            ttc = EnvmGenObjectList_aObject_1_Kinematic_fDistX / (
                    EnvmGenObjectList_aObject_1_Kinematic_fVabsX - IDB3_VehicleSpd / 3.6)
            IDB3_VehicleSpd_flag = IDB3_VehicleSpd / 3.6
            if (IDB3_VehicleSpd_flag <= 1 and ttc < 0.8) or (
                    IDB3_VehicleSpd_flag <= 3 and (ttc < 0.25 * IDB3_VehicleSpd_flag + 0.55)) or \
                    (IDB3_VehicleSpd_flag > 3 and IDB3_VehicleSpd_flag <= 10 and (
                            ttc < 0.1 * IDB3_VehicleSpd_flag + 1)) or \
                    (IDB3_VehicleSpd_flag > 10 and ttc < 2):
                level1 = "NNP退出"
                level2 = "触发时刻"
                level3 = "与高亮目标ttc过小"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)
            gap = EnvmGenObjectList_aObject_1_Kinematic_fDistX / (IDB3_VehicleSpd / 3.6)
            if (IDB3_VehicleSpd_flag <= 1 and gap < 1) or (
                    IDB3_VehicleSpd_flag <= 10 and gap < -0.092857143 * IDB3_VehicleSpd_flag + 1.278571429) or \
                    (
                            IDB3_VehicleSpd_flag > 10 and IDB3_VehicleSpd_flag <= 30 and gap < -0.0085 * IDB3_VehicleSpd_flag + 0.435):
                level1 = "NNP退出"
                level2 = "触发时刻"
                level3 = "与高亮目标time_gap过小"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)
        elif VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID == 2:
            ttc = EnvmGenObjectList_aObject_2_Kinematic_fDistX / (
                    EnvmGenObjectList_aObject_2_Kinematic_fVabsX - IDB3_VehicleSpd / 3.6)
            IDB3_VehicleSpd_flag = IDB3_VehicleSpd / 3.6
            if (IDB3_VehicleSpd_flag <= 1 and ttc < 0.8) or (
                    IDB3_VehicleSpd_flag <= 3 and (ttc < 0.25 * IDB3_VehicleSpd_flag + 0.55)) or \
                    (IDB3_VehicleSpd_flag > 3 and IDB3_VehicleSpd_flag <= 10 and (
                            ttc < 0.1 * IDB3_VehicleSpd_flag + 1)) or \
                    (IDB3_VehicleSpd_flag > 10 and ttc < 2):
                level1 = "NNP退出"
                level2 = "触发时刻"
                level3 = "与高亮目标ttc过小"

                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)

            gap = EnvmGenObjectList_aObject_2_Kinematic_fDistX / (IDB3_VehicleSpd / 3.6)
            if (IDB3_VehicleSpd_flag <= 1 and gap < 1) or (
                    IDB3_VehicleSpd_flag <= 10 and gap < -0.092857143 * IDB3_VehicleSpd_flag + 1.278571429) or \
                    (
                            IDB3_VehicleSpd_flag > 10 and IDB3_VehicleSpd_flag <= 30 and gap < -0.0085 * IDB3_VehicleSpd_flag + 0.435):
                level1 = "NNP退出"
                level2 = "触发时刻"
                level3 = "与高亮目标time_gap过小"

                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)
        elif VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID == 3:
            ttc = EnvmGenObjectList_aObject_3_Kinematic_fDistX / (
                    EnvmGenObjectList_aObject_3_Kinematic_fVabsX - IDB3_VehicleSpd / 3.6)
            IDB3_VehicleSpd_flag = IDB3_VehicleSpd / 3.6
            if (IDB3_VehicleSpd_flag <= 1 and ttc < 0.8) or (
                    IDB3_VehicleSpd_flag <= 3 and (ttc < 0.25 * IDB3_VehicleSpd_flag + 0.55)) or \
                    (IDB3_VehicleSpd_flag > 3 and IDB3_VehicleSpd_flag <= 10 and (
                            ttc < 0.1 * IDB3_VehicleSpd_flag + 1)) or \
                    (IDB3_VehicleSpd_flag > 10 and ttc < 2):
                level1 = "AEB激活"
                level2 = "触发时刻"
                level3 = "与高亮目标ttc过小"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)

            gap = EnvmGenObjectList_aObject_3_Kinematic_fDistX / (IDB3_VehicleSpd / 3.6)
            if (IDB3_VehicleSpd_flag <= 1 and gap < 1) or (
                    IDB3_VehicleSpd_flag <= 10 and gap < -0.092857143 * IDB3_VehicleSpd_flag + 1.278571429) or \
                    (
                            IDB3_VehicleSpd_flag > 10 and IDB3_VehicleSpd_flag <= 30 and gap < -0.0085 * IDB3_VehicleSpd_flag + 0.435):
                level1 = "AEB激活"
                level2 = "触发时刻"
                level3 = "与高亮目标time_gap过小"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)
        elif VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID == 4:
            ttc = EnvmGenObjectList_aObject_4_Kinematic_fDistX / (
                    EnvmGenObjectList_aObject_4_Kinematic_fVabsX - IDB3_VehicleSpd / 3.6)
            IDB3_VehicleSpd_flag = IDB3_VehicleSpd / 3.6
            if (IDB3_VehicleSpd_flag <= 1 and ttc < 0.8) or (
                    IDB3_VehicleSpd_flag <= 3 and (ttc < 0.25 * IDB3_VehicleSpd_flag + 0.55)) or \
                    (IDB3_VehicleSpd_flag > 3 and IDB3_VehicleSpd_flag <= 10 and (
                            ttc < 0.1 * IDB3_VehicleSpd_flag + 1)) or \
                    (IDB3_VehicleSpd_flag > 10 and ttc < 2):
                level1 = "AEB激活"
                level2 = "触发时刻"
                level3 = "与高亮目标ttc过小"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)

            gap = EnvmGenObjectList_aObject_4_Kinematic_fDistX / (IDB3_VehicleSpd / 3.6)
            if (IDB3_VehicleSpd_flag <= 1 and gap < 1) or (
                    IDB3_VehicleSpd_flag <= 10 and gap < -0.092857143 * IDB3_VehicleSpd_flag + 1.278571429) or \
                    (
                            IDB3_VehicleSpd_flag > 10 and IDB3_VehicleSpd_flag <= 30 and gap < -0.0085 * IDB3_VehicleSpd_flag + 0.435):
                level1 = "AEB激活"
                level2 = "触发时刻"
                level3 = "与高亮目标time_gap过小"

                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)
        elif VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID == 5:
            ttc = EnvmGenObjectList_aObject_5_Kinematic_fDistX / (
                    EnvmGenObjectList_aObject_5_Kinematic_fVabsX - IDB3_VehicleSpd / 3.6)
            IDB3_VehicleSpd_flag = IDB3_VehicleSpd / 3.6
            if (IDB3_VehicleSpd_flag <= 1 and ttc < 0.8) or (
                    IDB3_VehicleSpd_flag <= 3 and (ttc < 0.25 * IDB3_VehicleSpd_flag + 0.55)) or \
                    (IDB3_VehicleSpd_flag > 3 and IDB3_VehicleSpd_flag <= 10 and (
                            ttc < 0.1 * IDB3_VehicleSpd_flag + 1)) or \
                    (IDB3_VehicleSpd_flag > 10 and ttc < 2):
                level1 = "AEB激活"
                level2 = "触发时刻"
                level3 = "与高亮目标ttc过小"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)

            gap = EnvmGenObjectList_aObject_5_Kinematic_fDistX / (IDB3_VehicleSpd / 3.6)
            if (IDB3_VehicleSpd_flag <= 1 and gap < 1) or (
                IDB3_VehicleSpd_flag <= 10 and gap < -0.092857143 * IDB3_VehicleSpd_flag + 1.278571429) or \
                (IDB3_VehicleSpd_flag > 10 and IDB3_VehicleSpd_flag <= 30 and gap < -0.0085 * IDB3_VehicleSpd_flag + 0.435):
                level1 = "AEB激活"
                level2 = "触发时刻"
                level3 = "与高亮目标time_gap过小"

                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)
        if (AccDisplayObj_CONTROL_ACCEL < -4.6 and IDB3_VehicleSpd / 3.6 <= 5) or \
                ((
                         IDB3_VehicleSpd / 3.6 > 5 and IDB3_VehicleSpd / 3.6 <= 20) and AccDisplayObj_CONTROL_ACCEL < 0.066666667 * (
                         IDB3_VehicleSpd / 3.6) - 4.933333333) or \
                (IDB3_VehicleSpd / 3.6 > 20 and AccDisplayObj_CONTROL_ACCEL < -3.6):
            level1 = "NNP退出"
            level2 = "触发时刻"
            level3 = "a_request过小"

            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)



    return dict_list
def get_scid_time(df_function_exit_can100ms,df_function_exit_canout):
    df_function_exit_can100ms_list = df_function_exit_can100ms[
        ['start_time_str', 'path', 'nsecs', 'VLCCDHypotheses_Hypothesis_0_fTTC', 'VLCCDHypotheses_Hypothesis_0_fDistX',
         'VLCCDHypotheses_Hypothesis_0_fDistY',
         'VLCCDHypotheses_Hypothesis_0_fVrelX', 'VLCCDHypotheses_Hypothesis_0_fVrelY', 'IDB3_VehicleSpd',
         'ACU2_LongAccSensorValue', 'ACU2_LatAccSensorValue',
         'ACU2_VehicleDynYawRate', 'IDB1_BrakePedalApplied', 'EPS1_SteerAngleSpd',
         'CamLaneData_CourseInfo_1_CourseInfoSegNear_f_C0','ICU2_Odometer','EPS1_TorsionBarTorque','CS1_GearPositionReqSt'
         ]].values.tolist()
    df_function_exit_canout_list = df_function_exit_canout[
        ['start_time_str', 'path', 'nsecs',
         'ADCS12_NNP_State_Reminder', 'ADCS12_NNP_RINO'
         ]].values.tolist()

    found_index = -9999
    found_start_time_str = ""
    found_nsecs=0
    # 遍历列表
    for index, element in enumerate(df_function_exit_canout_list):
        start_time_str = element[0]
        path = element[1]
        nsecs = element[2]
        ADCS12_NNP_State_Reminder = element[3]
        ADCS12_NNP_RINO = element[4]
        if (ADCS12_NNP_State_Reminder in [5,6,7]) or (ADCS12_NNP_RINO==6):
            found_index = index
            found_start_time_str=start_time_str
            found_nsecs=nsecs
            break  # 找到第一个符合条件的元素就跳出循环
    logging.info("found_index: " + str(found_index))
    logging.info("found_nsecs: " + str(found_nsecs))

    list_data,index_100ms=get_can_100ms_list(df_function_exit_can100ms_list, found_index,found_start_time_str)
    found_ICU2_Odometer = list_data[15]
    found_IDB3_VehicleSpd = list_data[8]
    found_ACU2_LongAccSensorValue = list_data[9]
    found_ACU2_LatAccSensorValue = list_data[10]
    found_ACU2_VehicleDynYawRate = list_data[11]
    found_EPS1_SteerAngleSpd = list_data[13]
    found_lane_curvature = list_data[14]
    found_EPS1_TorsionBarTorque = list_data[16]
    found_CS1_GearPositionReqSt = list_data[17]

    dict_scid={}
    dict_scid["scid_start_time_str"]=start_time_str
    dict_scid["ICU2_Odometer"] = found_ICU2_Odometer
    dict_scid["IDB3_VehicleSpd"] = found_IDB3_VehicleSpd
    dict_scid["ACU2_LongAccSensorValue"] = found_ACU2_LongAccSensorValue
    dict_scid["ACU2_LatAccSensorValue"] = found_ACU2_LatAccSensorValue
    dict_scid["ACU2_VehicleDynYawRate"] = found_ACU2_VehicleDynYawRate
    dict_scid["EPS1_SteerAngleSpd"] = found_EPS1_SteerAngleSpd
    dict_scid["lane_curvature"] = found_lane_curvature
    dict_scid["EPS1_TorsionBarTorque"] = found_EPS1_TorsionBarTorque
    dict_scid["CS1_GearPositionReqSt"] = found_CS1_GearPositionReqSt
    dict_scid["found_nsecs"] = found_nsecs
    return dict_scid
def get_can_100ms_list(df_can_100ms_list,nsecs,start_time):
    subset_list = [item for item in df_can_100ms_list if item[0] == start_time]
    if not subset_list:
        # 处理找不到匹配start_time的情况
        return None
    # 找到最接近目标值的行数据
    closest_data = min(subset_list, key=lambda x: abs(x[2] - nsecs))

    # 获取最接近值的索引
    index = df_can_100ms_list.index(closest_data)

    # 打印结果
    return  closest_data,index
def get_model_feature(found_index,df_list,start_time_str):
    if found_index >= 11:
        VLCCDHypotheses_Hypothesis_0_fTTC_last_list = df_list[found_index - 11:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fTTC_last= [row[3] for row in VLCCDHypotheses_Hypothesis_0_fTTC_last_list]
        VLCCDHypotheses_Hypothesis_0_fTTC_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fTTC_last)
        AEB_Target_Estimated_Time_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fTTC_last_nnp)

        VLCCDHypotheses_Hypothesis_0_fTTC_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fTTC_next =[row[3] for row in VLCCDHypotheses_Hypothesis_0_fTTC_next_list]
        VLCCDHypotheses_Hypothesis_0_fTTC_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fTTC_next)
        AEB_Target_Estimated_Time_post = np.mean(VLCCDHypotheses_Hypothesis_0_fTTC_next_nnp)

        VLCCDHypotheses_Hypothesis_0_fDistX_last_list = df_list[found_index - 11:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fDistX_last= [row[4] for row in VLCCDHypotheses_Hypothesis_0_fDistX_last_list]
        VLCCDHypotheses_Hypothesis_0_fDistX_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fDistX_last)
        AEB_Target_Longitudinal_Distance_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fDistX_last_nnp)


        VLCCDHypotheses_Hypothesis_0_fDistX_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fDistX_next= [row[4] for row in VLCCDHypotheses_Hypothesis_0_fDistX_next_list]
        VLCCDHypotheses_Hypothesis_0_fDistX_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fDistX_next)
        AEB_Target_Longitudinal_Distance_post = np.mean(VLCCDHypotheses_Hypothesis_0_fDistX_next_nnp)

        VLCCDHypotheses_Hypothesis_0_fDistY_last_list = df_list[found_index - 11:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fDistY_last = [row[5] for row in VLCCDHypotheses_Hypothesis_0_fDistY_last_list]
        VLCCDHypotheses_Hypothesis_0_fDistY_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fDistY_last)
        AEB_Target_Cross_Range_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fDistY_last_nnp)

        VLCCDHypotheses_Hypothesis_0_fDistY_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fDistY_next = [row[5] for row in VLCCDHypotheses_Hypothesis_0_fDistY_next_list]
        VLCCDHypotheses_Hypothesis_0_fDistY_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fDistY_next)
        AEB_Target_Cross_Range_post = np.mean(VLCCDHypotheses_Hypothesis_0_fDistY_next_nnp)

        VLCCDHypotheses_Hypothesis_0_fVrelX_last_list = df_list[found_index - 11:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fVrelX_last = [row[6] for row in VLCCDHypotheses_Hypothesis_0_fVrelX_last_list]
        VLCCDHypotheses_Hypothesis_0_fVrelX_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fVrelX_last)
        AEB_Target_Longitudinal_Velocity_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fVrelX_last_nnp)

        VLCCDHypotheses_Hypothesis_0_fVrelX_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fVrelX_next = [row[6] for row in VLCCDHypotheses_Hypothesis_0_fVrelX_next_list]
        VLCCDHypotheses_Hypothesis_0_fVrelX_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fVrelX_next)
        AEB_Target_Longitudinal_Velocity_post = np.mean(VLCCDHypotheses_Hypothesis_0_fVrelX_next_nnp)

        VLCCDHypotheses_Hypothesis_0_fVrelY_last_list = df_list[found_index - 11:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fVrelY_last = [row[7] for row in VLCCDHypotheses_Hypothesis_0_fVrelY_last_list]
        VLCCDHypotheses_Hypothesis_0_fVrelY_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fVrelY_last)
        AEB_Target_Lateral_Velocity_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fVrelY_last_nnp)

        VLCCDHypotheses_Hypothesis_0_fVrelY_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fVrelY_next = [row[7] for row in VLCCDHypotheses_Hypothesis_0_fVrelY_next_list]
        VLCCDHypotheses_Hypothesis_0_fVrelY_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fVrelY_next)
        AEB_Target_Lateral_Velocity_post = np.mean(VLCCDHypotheses_Hypothesis_0_fVrelY_next_nnp)

        IDB3_VehicleSpd_last_list = df_list[found_index - 11:found_index - 1]
        IDB3_VehicleSpd_last = [row[8] for row in IDB3_VehicleSpd_last_list]
        IDB3_VehicleSpd_last_nnp = np.array(IDB3_VehicleSpd_last)
        IDB3_VehicleSpd_pre = np.mean(IDB3_VehicleSpd_last_nnp)

        IDB3_VehicleSpd_last_next_list = df_list[found_index + 1:found_index + 11]
        IDB3_VehicleSpd_last_next = [row[8] for row in IDB3_VehicleSpd_last_next_list]
        IDB3_VehicleSpd_last_next_nnp = np.array(IDB3_VehicleSpd_last_next)
        IDB3_VehicleSpd_post = np.mean(IDB3_VehicleSpd_last_next_nnp)

        ACU2_LongAccSensorValue_last_list = df_list[found_index - 11:found_index - 1]
        ACU2_LongAccSensorValue_last = [row[9] for row in ACU2_LongAccSensorValue_last_list]
        ACU2_LongAccSensorValue_last_nnp = np.array(ACU2_LongAccSensorValue_last)
        ACU2_LongAccSensorValue_pre = np.mean(ACU2_LongAccSensorValue_last_nnp)

        ACU2_LongAccSensorValue_next_list = df_list[found_index + 1:found_index + 11]
        ACU2_LongAccSensorValue_next = [row[9] for row in ACU2_LongAccSensorValue_next_list]
        ACU2_LongAccSensorValue_next_nnp = np.array(ACU2_LongAccSensorValue_next)
        ACU2_LongAccSensorValue_post = np.mean(ACU2_LongAccSensorValue_next_nnp)

        ACU2_LatAccSensorValue_last_list = df_list[found_index - 11:found_index - 1]
        ACU2_LatAccSensorValue_last = [row[10] for row in ACU2_LatAccSensorValue_last_list]
        ACU2_LatAccSensorValue_last_nnp = np.array(ACU2_LatAccSensorValue_last)
        ACU2_LatAccSensorValue_pre = np.mean(ACU2_LatAccSensorValue_last_nnp)

        ACU2_LatAccSensorValue_next_list = df_list[found_index + 1:found_index + 11]
        ACU2_LatAccSensorValue_next = [row[10] for row in ACU2_LatAccSensorValue_next_list]
        ACU2_LatAccSensorValue_next_nnp = np.array(ACU2_LatAccSensorValue_next)
        ACU2_LatAccSensorValue_post = np.mean(ACU2_LatAccSensorValue_next_nnp)

        ACU2_VehicleDynYawRate_last_list = df_list[found_index - 11:found_index - 1]
        ACU2_VehicleDynYawRate_last = [row[11] for row in ACU2_VehicleDynYawRate_last_list]
        ACU2_VehicleDynYawRate_last_nnp = np.array(ACU2_VehicleDynYawRate_last)
        ACU2_VehicleDynYawRate_pre = np.mean(ACU2_VehicleDynYawRate_last_nnp)

        ACU2_VehicleDynYawRate_next_list = df_list[found_index + 1:found_index + 11]
        ACU2_VehicleDynYawRate_next = [row[11] for row in ACU2_VehicleDynYawRate_next_list]
        ACU2_VehicleDynYawRate_next_nnp = np.array(ACU2_VehicleDynYawRate_next)
        ACU2_VehicleDynYawRate_post = np.mean(ACU2_VehicleDynYawRate_next_nnp)

        AEB_Target_Estimated_Time_diff = AEB_Target_Estimated_Time_post - AEB_Target_Estimated_Time_pre
        AEB_Target_Longitudinal_Distance_diff = AEB_Target_Longitudinal_Distance_post - AEB_Target_Longitudinal_Distance_pre
        AEB_Target_Cross_Range_diff = AEB_Target_Cross_Range_post - AEB_Target_Cross_Range_pre
        AEB_Target_Longitudinal_Velocity_diff = AEB_Target_Longitudinal_Velocity_post - AEB_Target_Longitudinal_Velocity_pre
        AEB_Target_Lateral_Velocity_diff = AEB_Target_Lateral_Velocity_post - AEB_Target_Lateral_Velocity_pre
        IDB3_VehicleSpd_diff = IDB3_VehicleSpd_post - IDB3_VehicleSpd_pre
        ACU2_LongAccSensorValue_diff = ACU2_LongAccSensorValue_post - ACU2_LongAccSensorValue_pre
        ACU2_LatAccSensorValue_diff = ACU2_LatAccSensorValue_post - ACU2_LatAccSensorValue_pre
        ACU2_VehicleDynYawRate_diff = ACU2_VehicleDynYawRate_post - ACU2_VehicleDynYawRate_pre

        IDB1_BrakePedalApplied_next_list = df_list[found_index + 1:found_index + 11]
        IDB1_BrakePedalApplied_next = [row[12] for row in IDB1_BrakePedalApplied_next_list]
        IDB1_BrakePedalApplied_next_nnp = np.array(IDB1_BrakePedalApplied_next)
        IDB1_BrakePedalApplied = np.mean(IDB1_BrakePedalApplied_next_nnp)

        EPS1_SteerAngleSpd_next_list = df_list[found_index + 1:found_index + 11]
        EPS1_SteerAngleSpd_next = [row[13] for row in EPS1_SteerAngleSpd_next_list]
        EPS1_SteerAngleSpd_next_nnp = np.array(EPS1_SteerAngleSpd_next)
        EPS1_SteerAngleSpd = np.max(EPS1_SteerAngleSpd_next_nnp)

        if found_index - 31 >= 0:
            lane_curve_list_fat = df_list[found_index - 31:found_index - 1]
            lane_curve_list = [row[14] for row in lane_curve_list_fat]
        else:
            lane_curve_list_fat = df_list[0:found_index - 1]
            lane_curve_list = [row[14] for row in lane_curve_list_fat]
        lane_curve = max(map(abs, lane_curve_list))
        logging.info("lane_curve: "+str(lane_curve))

        hour = start_time_str[11:13]
        data = {'AEB_Target_Estimated_Time_pre': [AEB_Target_Estimated_Time_pre],
                'AEB_Target_Estimated_Time_post': [AEB_Target_Estimated_Time_post],
                'AEB_Target_Longitudinal_Distance_pre': [AEB_Target_Longitudinal_Distance_pre],
                'AEB_Target_Longitudinal_Distance_post': [AEB_Target_Longitudinal_Distance_post],
                'AEB_Target_Cross_Range_pre': [AEB_Target_Cross_Range_pre],
                'AEB_Target_Cross_Range_post': [AEB_Target_Cross_Range_post],
                'AEB_Target_Longitudinal_Velocity_pre': [AEB_Target_Longitudinal_Velocity_pre],
                'AEB_Target_Longitudinal_Velocity_post': [AEB_Target_Longitudinal_Velocity_post],
                'AEB_Target_Lateral_Velocity_pre': [AEB_Target_Lateral_Velocity_pre],
                'AEB_Target_Lateral_Velocity_post': [AEB_Target_Lateral_Velocity_post],
                'IDB3_VehicleSpd_pre': [IDB3_VehicleSpd_pre],
                'IDB3_VehicleSpd_post': [IDB3_VehicleSpd_post],
                'ACU2_LongAccSensorValue_pre': [ACU2_LongAccSensorValue_pre],
                'ACU2_LongAccSensorValue_post': [ACU2_LongAccSensorValue_post],
                'ACU2_LatAccSensorValue_pre': [ACU2_LatAccSensorValue_pre],
                'ACU2_LatAccSensorValue_post': [ACU2_LatAccSensorValue_post],
                'ACU2_VehicleDynYawRate_pre': [ACU2_VehicleDynYawRate_pre],
                'ACU2_VehicleDynYawRate_post': [ACU2_VehicleDynYawRate_post],
                'AEB_Target_Estimated_Time_diff': [AEB_Target_Estimated_Time_diff],
                'AEB_Target_Longitudinal_Distance_diff': [AEB_Target_Longitudinal_Distance_diff],
                'AEB_Target_Cross_Range_diff': [AEB_Target_Cross_Range_diff],
                'AEB_Target_Longitudinal_Velocity_diff': [AEB_Target_Longitudinal_Velocity_diff],
                'AEB_Target_Lateral_Velocity_diff': [AEB_Target_Lateral_Velocity_diff],
                'IDB3_VehicleSpd_diff': [IDB3_VehicleSpd_diff],
                'ACU2_LongAccSensorValue_diff': [ACU2_LongAccSensorValue_diff],
                'ACU2_LatAccSensorValue_diff': [ACU2_LatAccSensorValue_diff],
                'ACU2_VehicleDynYawRate_diff': [ACU2_VehicleDynYawRate_diff],
                'IDB1_BrakePedalApplied': [IDB1_BrakePedalApplied],
                'EPS1_SteerAngleSpd': [EPS1_SteerAngleSpd],
                'lane_curve': [lane_curve],
                'hour': [hour]
                }
        df = pd.DataFrame(data)
    else:
        VLCCDHypotheses_Hypothesis_0_fTTC_last_list = df_list[0:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fTTC_last= [row[3] for row in VLCCDHypotheses_Hypothesis_0_fTTC_last_list]
        VLCCDHypotheses_Hypothesis_0_fTTC_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fTTC_last)
        AEB_Target_Estimated_Time_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fTTC_last_nnp)

        VLCCDHypotheses_Hypothesis_0_fTTC_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fTTC_next =[row[3] for row in VLCCDHypotheses_Hypothesis_0_fTTC_next_list]
        VLCCDHypotheses_Hypothesis_0_fTTC_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fTTC_next)
        AEB_Target_Estimated_Time_post = np.mean(VLCCDHypotheses_Hypothesis_0_fTTC_next_nnp)

        VLCCDHypotheses_Hypothesis_0_fDistX_last_list = df_list[0:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fDistX_last= [row[4] for row in VLCCDHypotheses_Hypothesis_0_fDistX_last_list]
        VLCCDHypotheses_Hypothesis_0_fDistX_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fDistX_last)
        AEB_Target_Longitudinal_Distance_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fDistX_last_nnp)


        VLCCDHypotheses_Hypothesis_0_fDistX_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fDistX_next= [row[4] for row in VLCCDHypotheses_Hypothesis_0_fDistX_next_list]
        VLCCDHypotheses_Hypothesis_0_fDistX_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fDistX_next)
        AEB_Target_Longitudinal_Distance_post = np.mean(VLCCDHypotheses_Hypothesis_0_fDistX_next_nnp)

        VLCCDHypotheses_Hypothesis_0_fDistY_last_list = df_list[0:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fDistY_last = [row[5] for row in VLCCDHypotheses_Hypothesis_0_fDistY_last_list]
        VLCCDHypotheses_Hypothesis_0_fDistY_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fDistY_last)
        AEB_Target_Cross_Range_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fDistY_last_nnp)

        VLCCDHypotheses_Hypothesis_0_fDistY_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fDistY_next = [row[5] for row in VLCCDHypotheses_Hypothesis_0_fDistY_next_list]
        VLCCDHypotheses_Hypothesis_0_fDistY_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fDistY_next)
        AEB_Target_Cross_Range_post = np.mean(VLCCDHypotheses_Hypothesis_0_fDistY_next_nnp)

        VLCCDHypotheses_Hypothesis_0_fVrelX_last_list = df_list[0:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fVrelX_last = [row[6] for row in VLCCDHypotheses_Hypothesis_0_fVrelX_last_list]
        VLCCDHypotheses_Hypothesis_0_fVrelX_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fVrelX_last)
        AEB_Target_Longitudinal_Velocity_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fVrelX_last_nnp)

        VLCCDHypotheses_Hypothesis_0_fVrelX_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fVrelX_next = [row[6] for row in VLCCDHypotheses_Hypothesis_0_fVrelX_next_list]
        VLCCDHypotheses_Hypothesis_0_fVrelX_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fVrelX_next)
        AEB_Target_Longitudinal_Velocity_post = np.mean(VLCCDHypotheses_Hypothesis_0_fVrelX_next_nnp)

        VLCCDHypotheses_Hypothesis_0_fVrelY_last_list = df_list[0:found_index - 1]
        VLCCDHypotheses_Hypothesis_0_fVrelY_last = [row[7] for row in VLCCDHypotheses_Hypothesis_0_fVrelY_last_list]
        VLCCDHypotheses_Hypothesis_0_fVrelY_last_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fVrelY_last)
        AEB_Target_Lateral_Velocity_pre = np.mean(VLCCDHypotheses_Hypothesis_0_fVrelY_last_nnp)

        VLCCDHypotheses_Hypothesis_0_fVrelY_next_list = df_list[found_index + 1:found_index + 11]
        VLCCDHypotheses_Hypothesis_0_fVrelY_next = [row[7] for row in VLCCDHypotheses_Hypothesis_0_fVrelY_next_list]
        VLCCDHypotheses_Hypothesis_0_fVrelY_next_nnp = np.array(VLCCDHypotheses_Hypothesis_0_fVrelY_next)
        AEB_Target_Lateral_Velocity_post = np.mean(VLCCDHypotheses_Hypothesis_0_fVrelY_next_nnp)

        IDB3_VehicleSpd_last_list = df_list[0:found_index - 1]
        IDB3_VehicleSpd_last = [row[8] for row in IDB3_VehicleSpd_last_list]
        IDB3_VehicleSpd_last_nnp = np.array(IDB3_VehicleSpd_last)
        IDB3_VehicleSpd_pre = np.mean(IDB3_VehicleSpd_last_nnp)

        IDB3_VehicleSpd_last_next_list = df_list[found_index + 1:found_index + 11]
        IDB3_VehicleSpd_last_next = [row[8] for row in IDB3_VehicleSpd_last_next_list]
        IDB3_VehicleSpd_last_next_nnp = np.array(IDB3_VehicleSpd_last_next)
        IDB3_VehicleSpd_post = np.mean(IDB3_VehicleSpd_last_next_nnp)

        ACU2_LongAccSensorValue_last_list = df_list[0:found_index - 1]
        ACU2_LongAccSensorValue_last = [row[9] for row in ACU2_LongAccSensorValue_last_list]
        ACU2_LongAccSensorValue_last_nnp = np.array(ACU2_LongAccSensorValue_last)
        ACU2_LongAccSensorValue_pre = np.mean(ACU2_LongAccSensorValue_last_nnp)

        ACU2_LongAccSensorValue_next_list = df_list[found_index + 1:found_index + 11]
        ACU2_LongAccSensorValue_next = [row[9] for row in ACU2_LongAccSensorValue_next_list]
        ACU2_LongAccSensorValue_next_nnp = np.array(ACU2_LongAccSensorValue_next)
        ACU2_LongAccSensorValue_post = np.mean(ACU2_LongAccSensorValue_next_nnp)

        ACU2_LatAccSensorValue_last_list = df_list[0:found_index - 1]
        ACU2_LatAccSensorValue_last = [row[10] for row in ACU2_LatAccSensorValue_last_list]
        ACU2_LatAccSensorValue_last_nnp = np.array(ACU2_LatAccSensorValue_last)
        ACU2_LatAccSensorValue_pre = np.mean(ACU2_LatAccSensorValue_last_nnp)

        ACU2_LatAccSensorValue_next_list = df_list[found_index + 1:found_index + 11]
        ACU2_LatAccSensorValue_next = [row[10] for row in ACU2_LatAccSensorValue_next_list]
        ACU2_LatAccSensorValue_next_nnp = np.array(ACU2_LatAccSensorValue_next)
        ACU2_LatAccSensorValue_post = np.mean(ACU2_LatAccSensorValue_next_nnp)

        ACU2_VehicleDynYawRate_last_list = df_list[0:found_index - 1]
        ACU2_VehicleDynYawRate_last = [row[11] for row in ACU2_VehicleDynYawRate_last_list]
        ACU2_VehicleDynYawRate_last_nnp = np.array(ACU2_VehicleDynYawRate_last)
        ACU2_VehicleDynYawRate_pre = np.mean(ACU2_VehicleDynYawRate_last_nnp)

        ACU2_VehicleDynYawRate_next_list = df_list[found_index + 1:found_index + 11]
        ACU2_VehicleDynYawRate_next = [row[11] for row in ACU2_VehicleDynYawRate_next_list]
        ACU2_VehicleDynYawRate_next_nnp = np.array(ACU2_VehicleDynYawRate_next)
        ACU2_VehicleDynYawRate_post = np.mean(ACU2_VehicleDynYawRate_next_nnp)

        AEB_Target_Estimated_Time_diff = AEB_Target_Estimated_Time_post - AEB_Target_Estimated_Time_pre
        AEB_Target_Longitudinal_Distance_diff = AEB_Target_Longitudinal_Distance_post - AEB_Target_Longitudinal_Distance_pre
        AEB_Target_Cross_Range_diff = AEB_Target_Cross_Range_post - AEB_Target_Cross_Range_pre
        AEB_Target_Longitudinal_Velocity_diff = AEB_Target_Longitudinal_Velocity_post - AEB_Target_Longitudinal_Velocity_pre
        AEB_Target_Lateral_Velocity_diff = AEB_Target_Lateral_Velocity_post - AEB_Target_Lateral_Velocity_pre
        IDB3_VehicleSpd_diff = IDB3_VehicleSpd_post - IDB3_VehicleSpd_pre
        ACU2_LongAccSensorValue_diff = ACU2_LongAccSensorValue_post - ACU2_LongAccSensorValue_pre
        ACU2_LatAccSensorValue_diff = ACU2_LatAccSensorValue_post - ACU2_LatAccSensorValue_pre
        ACU2_VehicleDynYawRate_diff = ACU2_VehicleDynYawRate_post - ACU2_VehicleDynYawRate_pre

        IDB1_BrakePedalApplied_next_list = df_list[found_index + 1:found_index + 11]
        IDB1_BrakePedalApplied_next = [row[12] for row in IDB1_BrakePedalApplied_next_list]
        IDB1_BrakePedalApplied_next_nnp = np.array(IDB1_BrakePedalApplied_next)
        IDB1_BrakePedalApplied = np.mean(IDB1_BrakePedalApplied_next_nnp)

        EPS1_SteerAngleSpd_next_list = df_list[found_index + 1:found_index + 11]
        EPS1_SteerAngleSpd_next = [row[13] for row in EPS1_SteerAngleSpd_next_list]
        EPS1_SteerAngleSpd_next_nnp = np.array(EPS1_SteerAngleSpd_next)
        EPS1_SteerAngleSpd = np.max(EPS1_SteerAngleSpd_next_nnp)

        if found_index - 31 >= 0:
            lane_curve_list_fat = df_list[found_index - 31:found_index - 1]
            lane_curve_list = [row[14] for row in lane_curve_list_fat]
        else:
            lane_curve_list_fat = df_list[0:found_index - 1]
            lane_curve_list = [row[14] for row in lane_curve_list_fat]
        lane_curve = max(map(abs, lane_curve_list))
        logging.info("lane_curve: "+str(lane_curve))

        hour = start_time_str[11:13]
        data = {'AEB_Target_Estimated_Time_pre': [AEB_Target_Estimated_Time_pre],
                'AEB_Target_Estimated_Time_post': [AEB_Target_Estimated_Time_post],
                'AEB_Target_Longitudinal_Distance_pre': [AEB_Target_Longitudinal_Distance_pre],
                'AEB_Target_Longitudinal_Distance_post': [AEB_Target_Longitudinal_Distance_post],
                'AEB_Target_Cross_Range_pre': [AEB_Target_Cross_Range_pre],
                'AEB_Target_Cross_Range_post': [AEB_Target_Cross_Range_post],
                'AEB_Target_Longitudinal_Velocity_pre': [AEB_Target_Longitudinal_Velocity_pre],
                'AEB_Target_Longitudinal_Velocity_post': [AEB_Target_Longitudinal_Velocity_post],
                'AEB_Target_Lateral_Velocity_pre': [AEB_Target_Lateral_Velocity_pre],
                'AEB_Target_Lateral_Velocity_post': [AEB_Target_Lateral_Velocity_post],
                'IDB3_VehicleSpd_pre': [IDB3_VehicleSpd_pre],
                'IDB3_VehicleSpd_post': [IDB3_VehicleSpd_post],
                'ACU2_LongAccSensorValue_pre': [ACU2_LongAccSensorValue_pre],
                'ACU2_LongAccSensorValue_post': [ACU2_LongAccSensorValue_post],
                'ACU2_LatAccSensorValue_pre': [ACU2_LatAccSensorValue_pre],
                'ACU2_LatAccSensorValue_post': [ACU2_LatAccSensorValue_post],
                'ACU2_VehicleDynYawRate_pre': [ACU2_VehicleDynYawRate_pre],
                'ACU2_VehicleDynYawRate_post': [ACU2_VehicleDynYawRate_post],
                'AEB_Target_Estimated_Time_diff': [AEB_Target_Estimated_Time_diff],
                'AEB_Target_Longitudinal_Distance_diff': [AEB_Target_Longitudinal_Distance_diff],
                'AEB_Target_Cross_Range_diff': [AEB_Target_Cross_Range_diff],
                'AEB_Target_Longitudinal_Velocity_diff': [AEB_Target_Longitudinal_Velocity_diff],
                'AEB_Target_Lateral_Velocity_diff': [AEB_Target_Lateral_Velocity_diff],
                'IDB3_VehicleSpd_diff': [IDB3_VehicleSpd_diff],
                'ACU2_LongAccSensorValue_diff': [ACU2_LongAccSensorValue_diff],
                'ACU2_LatAccSensorValue_diff': [ACU2_LatAccSensorValue_diff],
                'ACU2_VehicleDynYawRate_diff': [ACU2_VehicleDynYawRate_diff],
                'IDB1_BrakePedalApplied': [IDB1_BrakePedalApplied],
                'EPS1_SteerAngleSpd': [EPS1_SteerAngleSpd],
                'lane_curve': [lane_curve],
                'hour': [hour]
                }
        df = pd.DataFrame(data)
        print(df)
    return df
def get_can_out_20ms_list(df_can_20ms_acc_active_list,nsecs):
    # 找到最接近目标值的行数据
    closest_data = min(df_can_20ms_acc_active_list, key=lambda x: abs(x[2] - nsecs))

    # 打印结果
    return  closest_data
def uploadjson(bucket_name,object_key,jsonstr):
    try:
        client = tos.TosClientV2(ak, sk, endpoint, region)
        # 若在上传对象时设置文件存储类型（x-tos-storage-class）和访问权限 (x-tos-acl), 请在 put_object中设置相关参数
        # 用户在上传对象时，可以自定义元数据，以便对对象进行自定义管理
        # result = client.put_object(bucket_name, object_key, content=content, acl=tos.ACLType.ACL_Private, storage_class=tos.StorageClassType.Storage_Class_Standard, meta={'name': '张三', 'age': '20'})
        result = client.put_object(bucket_name, object_key, content=jsonstr)
        # HTTP状态码
        print('http status code:{}'.format(result.status_code))
        # 请求ID。请求ID是本次请求的唯一标识，建议在日志中添加此参数
        print('request_id: {}'.format(result.request_id))
        # hash_crc64_ecma 表示该对象的64位CRC值, 可用于验证上传对象的完整性
        print('crc64: {}'.format(result.hash_crc64_ecma))
    except tos.exceptions.TosClientError as e:
        # 操作失败，捕获客户端异常，一般情况为非法请求参数或网络异常
        print('fail with client error, message:{}, cause: {}'.format(e.message, e.cause))
    except tos.exceptions.TosServerError as e:
        # 操作失败，捕获服务端异常，可从返回信息中获取详细错误信息
        print('fail with server error, code: {}'.format(e.code))
        # request id 可定位具体问题，强烈建议日志中保存
        print('error with request id: {}'.format(e.request_id))
        print('error with message: {}'.format(e.message))
        print('error with http code: {}'.format(e.status_code))
        print('error with ec: {}'.format(e.ec))
        print('error with request url: {}'.format(e.request_url))
    except Exception as e:
        print('fail with unknown error: {}'.format(e))
def get_timestamp(time_string):
    # 转换为时间元组
    time_tuple = time.strptime(time_string, "%Y-%m-%d %H:%M:%S")
    # 转换为时间戳
    timestamp = str(int(time.mktime(time_tuple)*1000))
    return timestamp
def add_to_mysql(json_str):
    # 配置数据库连接信息
    db_config = {
        'host': 'mysql-d8beb8b0655b-public.rds.volces.com',
        'user': 'user01',
        'password': 'password123!#',
        'database': 'bi_test'
    }
    # 创建数据库连接
    conn = mysql.connector.connect(**db_config)
    cursor = conn.cursor()

    # 假设你有一个名为 'your_table' 的表，包含 'column1', 'column2', 'column3' 等字段
    table_name = 'trigger_sc_ep40_tda4'

    # 假设你有一个数据字典，包含要插入的数据
    data_to_insert = json.loads(json_str)

    # 构建 SQL 插入语句
    columns = ', '.join(data_to_insert.keys())
    values = ', '.join(['%s'] * len(data_to_insert))
    sql_insert = f"replace into {table_name} ({columns}) VALUES ({values})"

    # 执行插入操作
    cursor.execute(sql_insert, list(data_to_insert.values()))

    # 提交更改
    conn.commit()
def convert_to_binary_with_length(number, desired_length):
    # 转成二进制
    binary_representation = bin(number)[2:]

    # 在二进制字符串前面补零，使其总长度为设定的长度
    binary_representation = binary_representation.zfill(desired_length)

    # 返回结果
    return binary_representation
def get_function_exit_label_can_out(df_100ms_save_path,pk_file_20ms,pk_file_out, vechicle_id,daystr,hourstr, bagid,uuids,file_type):
    try:
        df_acc_100ms = pd.read_pickle(df_100ms_save_path)
        print(df_acc_100ms.columns)
    except Exception as e:
        print('data report read error, ', str(e))
    try:
        df_acc_20ms = pd.read_pickle(pk_file_20ms)
        print(df_acc_20ms.columns)
    except Exception as e:
        print('data report read error, ', str(e))

    df_function_exit_100ms_list= df_acc_100ms[
        ['start_time_str','IDB1_BrakePedalApplied','IDB1_BrakePedalAppliedV','ADCS2_AEBPartialBrake','ADCS2_AEBFullBrake',
         'ADCS8_ACCState','path','ADCS12_longitudCtrlSysInfo','ADCS12_longitudDisableInfo',
         'ICU2_Odometer','IDB3_VehicleSpd','ACU2_LongAccSensorValue','ACU2_LatAccSensorValue','ACU2_VehicleDynYawRate','EPS1_SteerAngleSpd'
         ,'EPS1_TorsionBarTorque','CS1_GearPositionReqSt','nsecs','AccDisplayObj_CONTROL_ACCEL',
         'CamLaneData_CourseInfo_1_CourseInfoSegNear_f_Length','CamLaneData_CourseInfo_2_CourseInfoSegNear_f_Length','CamLaneData_LaneMarkerInfo_1_f_MarkerDist','CamLaneData_LaneMarkerInfo_2_f_MarkerDist',
         'g_LCF_TJASA_Output_TJASTM_SysStateTJA_nu','g_LCFSEN_proDebugs_sTJASADebug_TJALKA_StrongReady_bool','g_LCFSEN_proDebugs_sTJASADebug_TJALKA_WeakReady_bool','g_LCFSEN_proDebugs_sTJASADebug_TJALKA_LaneCenterInvalid_btf'


         ]].values.tolist()
    try:
        df_function_exit_canout = pd.read_pickle(pk_file_out)
    except Exception as e:
        print('data report read error, ', str(e))

    df_function_exit_canout_list= df_function_exit_canout[
        ['start_time_str', 'path', 'nsecs','ADCS12_NNP_State_Reminder','ADCS12_NNP_RINO','NNP_out_reserved8']].values.tolist()

    df_can_20ms_list = df_acc_20ms[
        ['start_time_str', 'path', 'VLCAccOOIData_AccOOINextLong_Attributes_uiObjectID',
         'EnvmGenObjectList_aObject_0_Kinematic_fAabsX', 'EnvmGenObjectList_aObject_0_Kinematic_fAabsY',
         'EnvmGenObjectList_aObject_0_Kinematic_fDistX', 'EnvmGenObjectList_aObject_0_Kinematic_fDistY',
         'EnvmGenObjectList_aObject_0_Kinematic_fVabsX', 'EnvmGenObjectList_aObject_0_Kinematic_fVabsY',
         'EnvmGenObjectList_aObject_1_Kinematic_fAabsX', 'EnvmGenObjectList_aObject_1_Kinematic_fAabsY',
         'EnvmGenObjectList_aObject_1_Kinematic_fDistX', 'EnvmGenObjectList_aObject_1_Kinematic_fDistY',
         'EnvmGenObjectList_aObject_1_Kinematic_fVabsX', 'EnvmGenObjectList_aObject_1_Kinematic_fVabsY',
         'EnvmGenObjectList_aObject_2_Kinematic_fAabsX', 'EnvmGenObjectList_aObject_2_Kinematic_fAabsY',
         'EnvmGenObjectList_aObject_2_Kinematic_fDistX', 'EnvmGenObjectList_aObject_2_Kinematic_fDistY',
         'EnvmGenObjectList_aObject_2_Kinematic_fVabsX', 'EnvmGenObjectList_aObject_2_Kinematic_fVabsY',
         'EnvmGenObjectList_aObject_3_Kinematic_fAabsX', 'EnvmGenObjectList_aObject_3_Kinematic_fAabsY',
         'EnvmGenObjectList_aObject_3_Kinematic_fDistX', 'EnvmGenObjectList_aObject_3_Kinematic_fDistY',
         'EnvmGenObjectList_aObject_3_Kinematic_fVabsX', 'EnvmGenObjectList_aObject_3_Kinematic_fVabsY',
         'EnvmGenObjectList_aObject_4_Kinematic_fAabsX', 'EnvmGenObjectList_aObject_4_Kinematic_fAabsY',
         'EnvmGenObjectList_aObject_4_Kinematic_fDistX', 'EnvmGenObjectList_aObject_4_Kinematic_fDistY',
         'EnvmGenObjectList_aObject_4_Kinematic_fVabsX', 'EnvmGenObjectList_aObject_4_Kinematic_fVabsY',
         'EnvmGenObjectList_aObject_5_Kinematic_fAabsX', 'EnvmGenObjectList_aObject_5_Kinematic_fAabsY',
         'EnvmGenObjectList_aObject_5_Kinematic_fDistX', 'EnvmGenObjectList_aObject_5_Kinematic_fDistY',
         'EnvmGenObjectList_aObject_5_Kinematic_fVabsX', 'EnvmGenObjectList_aObject_5_Kinematic_fVabsY','SuppressReason'
         ]].values.tolist()

    #获取触发状态：
    dict_list=[]
    scid_dict=get_scid_time(df_acc_100ms, df_function_exit_canout)
    found_index=-9999
    found_nsecs=0
    found_start_time=""
    for index, element in enumerate(df_function_exit_canout_list):
        start_time_str = element[0]
        path = element[1]
        nsecs = element[2]
        ADCS12_NNP_State_Reminder = element[3]
        ADCS12_NNP_RINO = element[4]
        if (ADCS12_NNP_State_Reminder in [5,6,7]) or (ADCS12_NNP_RINO==6):
            found_index = index
            found_nsecs=nsecs
            found_start_time=start_time_str
            break  # 找到第一个符合条件的元素就跳出循环
    logging.info("found_index: " + str(found_index))
    logging.info("found_nsecs: " + str(found_nsecs))

    dict_list=get_ttc(df_can_20ms_list, df_function_exit_100ms_list, found_nsecs, vechicle_id, bagid, scid_dict, dict_list,found_start_time)


    ADCS12_NNP_State_Reminder_last=df_function_exit_canout_list[0][3]
    ADCS12_NNP_RINO_last=df_function_exit_canout_list[0][4]
    for row in df_function_exit_canout_list:
        start_time_str=row[0]
        path=row[1]
        nsecs=row[2]
        ADCS12_NNP_State_Reminder =row[3]
        ADCS12_NNP_RINO=row[4]
        NNP_out_reserved8=row[5]

        if ADCS12_NNP_State_Reminder_last!=5 and ADCS12_NNP_State_Reminder==5:
            level1 = "NNP退出"
            level2 = "NNP即将退出"
            level3 = ""
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)
        if ADCS12_NNP_State_Reminder_last!=6 and ADCS12_NNP_State_Reminder==6:
            level1 = "NNP退出"
            level2 = "NNP退出"
            level3 = ""
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)

        if ADCS12_NNP_State_Reminder_last!=7 and ADCS12_NNP_State_Reminder==7:
            level1 = "NNP退出"
            level2 = "故障退出"
            level3 = ""
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)

        if ADCS12_NNP_RINO_last!=6 and ADCS12_NNP_RINO==6:
            level1 = "NNP退出"
            level2 = "导航任务接管"
            level3 = ""
            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
            data_list = get_dict_list(dict)
            dict_list.append(data_list)

        if ADCS12_NNP_State_Reminder_last not in [5,6,7] and ADCS12_NNP_State_Reminder in [5,6,7]:
            binary_representation = get_binary_with_16(NNP_out_reserved8)
            # 根据每个位的值设置相应的变量
            Bite0 = int(binary_representation[-1])
            Bite1 = int(binary_representation[-2])
            Bite2 = int(binary_representation[-3])
            Bite3 = int(binary_representation[-4])
            Bite4 = int(binary_representation[-5])
            Bite5 = int(binary_representation[-6])
            Bite6 = int(binary_representation[-7])
            Bite7 = int(binary_representation[-8])
            Bite8 = int(binary_representation[-9])
            Bite9 = int(binary_representation[-10])
            Bite10 = int(binary_representation[-11])
            Bite11 = int(binary_representation[-12])
            Bite12 = int(binary_representation[-13])
            Bite13 = int(binary_representation[-14])
            Bite14 = int(binary_representation[-15])
            Bite15 = int(binary_representation[-16])
            if Bite15:
                level1 = "NNP退出"
                level2 = "NNP异常退出"
                level3 = "原因：FCA ERROR"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)
            if Bite14:
                level1 = "NNP退出"
                level2 = "NNP异常退出"
                level3 = "原因：RCA ERROR"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)

            if Bite13:
                level1 = "NNP退出"
                level2 = "NNP异常退出"
                level3 = "原因：FCB ERROR"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)

            if Bite12:
                level1 = "NNP退出"
                level2 = "NNP异常退出"
                level3 = "原因：Vehicle Velocity > 140kph"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)

            if Bite11:
                level1 = "NNP退出"
                level2 = "NNP异常退出"
                level3 = "原因：Manual Torque Override"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)

            if Bite10:
                level1 = "NNP退出"
                level2 = "NNP异常退出"
                level3 = "原因：Brake pedal pressed Hazrd light on"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)

            if Bite9:
                level1 = "NNP退出"
                level2 = "NNP异常退出"
                level3 = "原因：ACC invalid"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)

            if Bite8:
                level1 = "NNP退出"
                level2 = "NNP异常退出"
                level3 = "原因：APSM quit to S4"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)
            if Bite7:
                level1 = "NNP退出"
                level2 = "NNP异常退出"
                level3 = "原因：Navigation info quit || invalid"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)

            if Bite6:
                level1 = "NNP退出"
                level2 = "NNP异常退出"
                level3 = "原因：Position info invalid more than 1 secs"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)

            if Bite5:
                level1 = "NNP退出"
                level2 = "NNP异常退出"
                level3 = "原因：HDmap EgoLane Heading not small than max"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)

            if Bite4:
                level1 = "NNP退出"
                level2 = "NNP异常退出"
                level3 = "原因：HDmap not valid road can not drive"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)

            if Bite3:
                level1 = "NNP退出"
                level2 = "NNP异常退出"
                level3 = "原因：HDmap EgoLane Width not large than min || Curve not less than"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)

            if Bite2:
                level1 = "NNP退出"
                level2 = "NNP异常退出"
                level3 = "原因：HDmap EgoLane Quality is not valid"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)

            if Bite1:
                level1 = "NNP退出"
                level2 = "NNP异常退出"
                level3 = "原因：NNP is CoolingDown, wait for resume"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)

            if Bite0:
                level1 = "NNP退出"
                level2 = "NNP异常退出"
                level3 = "原因：Pilot function quit"
                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                data_list = get_dict_list(dict)
                dict_list.append(data_list)

                lis_data_100ms,index_100ms=get_can_100ms_list(df_function_exit_100ms_list,nsecs,start_time_str)
                if lis_data_100ms is not None and len(lis_data_100ms) > 0:
                    ADCS8_ACCState = lis_data_100ms[5]
                    CamLaneData_CourseInfo_1_CourseInfoSegNear_f_Length = lis_data_100ms[19]
                    CamLaneData_CourseInfo_2_CourseInfoSegNear_f_Length = lis_data_100ms[20]
                    CamLaneData_LaneMarkerInfo_1_f_MarkerDist = lis_data_100ms[21]
                    CamLaneData_LaneMarkerInfo_2_f_MarkerDist = lis_data_100ms[22]
                    g_LCF_TJASA_Output_TJASTM_SysStateTJA_nu = lis_data_100ms[23]
                    g_LCFSEN_proDebugs_sTJASADebug_TJALKA_StrongReady_bool = lis_data_100ms[24]
                    g_LCFSEN_proDebugs_sTJASADebug_TJALKA_WeakReady_bool = lis_data_100ms[25]
                    g_LCFSEN_proDebugs_sTJASADebug_TJALKA_LaneCenterInvalid_btf = lis_data_100ms[26]

                    if ADCS8_ACCState not in [1, 2]:
                        level1 = "NNP退出"
                        level2 = "NNP异常退出"
                        level3 = "原因：不满足ACC激活条件"
                        dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                        data_list = get_dict_list(dict)
                        dict_list.append(data_list)

                        list_dat_20ms, index_20ms = get_can_20ms_list(df_can_20ms_list, nsecs, start_time_str)
                        if list_dat_20ms is not None and len(list_dat_20ms) > 0:
                            SuppressReason = list_dat_20ms[39]
                            SuppressReason_arr = get_binary_with_27(SuppressReason)
                            # 根据每个位的值设置相应的变量
                            Bite0 = int(SuppressReason_arr[-1])
                            Bite1 = int(SuppressReason_arr[-2])
                            Bite2 = int(SuppressReason_arr[-3])
                            Bite3 = int(SuppressReason_arr[-4])
                            Bite4 = int(SuppressReason_arr[-5])
                            Bite5 = int(SuppressReason_arr[-6])
                            Bite6 = int(SuppressReason_arr[-7])
                            Bite7 = int(SuppressReason_arr[-8])
                            Bite8 = int(SuppressReason_arr[-9])
                            Bite9 = int(SuppressReason_arr[-10])
                            Bite10 = int(SuppressReason_arr[-11])
                            Bite11 = int(SuppressReason_arr[-12])
                            Bite12 = int(SuppressReason_arr[-13])
                            Bite13 = int(SuppressReason_arr[-14])
                            Bite14 = int(SuppressReason_arr[-15])
                            Bite15 = int(SuppressReason_arr[-16])
                            Bite16 = int(SuppressReason_arr[-17])
                            Bite17 = int(SuppressReason_arr[-18])
                            Bite18 = int(SuppressReason_arr[-19])
                            Bite19 = int(SuppressReason_arr[-20])
                            Bite20 = int(SuppressReason_arr[-21])
                            Bite21 = int(SuppressReason_arr[-22])
                            Bite22 = int(SuppressReason_arr[-23])
                            Bite23 = int(SuppressReason_arr[-24])
                            Bite24 = int(SuppressReason_arr[-25])
                            Bite25 = int(SuppressReason_arr[-26])
                            Bite26 = int(SuppressReason_arr[-27])

                            if Bite0:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：ACCreset"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)
                            if Bite1:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：诊断出故障"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)
                            if Bite2:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：无目标时车速低于 15"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)
                            if Bite3:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：ABS,ESC,TCS,ARP 激活"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite4:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：解安全带"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite5:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：车速过高"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)
                            if Bite6:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：曲率过大"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite7:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：加速度过大"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite8:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：四门两盖"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite9:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：踩制动"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite10:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：VCU ACC not ready"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite11:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：ACC not enable IDB5_ACC _Enable"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite12:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：EPB not allow"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite13:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：Act gear 不在驱动档或无效"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite14:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：后溜"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite15:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：AEB 或相关激活"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite16:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：IDB7_DynParkBrkByIDBActive"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite17:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：HDC 激活，TCS 不可用"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite18:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：泊车系统"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite19:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：ACC_ReqLim==0x03 或制动盘过热或 ABS EBD ESC TCS fail"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite20:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：油门无效或 standstill 无效"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite21:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：横向加速度纵向加速度 yawrate 无效"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite22:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：车轮方向无效"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite23:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：转向角信号无效"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite24:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：故障诊断的抑制信号"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite25:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：融合目标时间戳不变导致故障"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)

                            if Bite26:
                                level1 = "NNP退出"
                                level2 = "NNP异常退出"
                                level3 = "原因：融合线时间戳不变导致故障"
                                dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2,
                                                level3)
                                data_list = get_dict_list(dict)
                                dict_list.append(data_list)




                    if CamLaneData_CourseInfo_1_CourseInfoSegNear_f_Length < 15 or CamLaneData_CourseInfo_2_CourseInfoSegNear_f_Length < 15:
                        level1 = "NNP退出"
                        level2 = "NNP异常退出"
                        level3 = "原因：车道线长度不满足"
                        dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                        data_list = get_dict_list(dict)
                        dict_list.append(data_list)
                    if abs(
                            CamLaneData_LaneMarkerInfo_1_f_MarkerDist - CamLaneData_LaneMarkerInfo_2_f_MarkerDist) < 2.6 or abs(
                            CamLaneData_LaneMarkerInfo_1_f_MarkerDist - CamLaneData_LaneMarkerInfo_2_f_MarkerDist) > 5.2:
                        level1 = "NNP退出"
                        level2 = "NNP异常退出"
                        level3 = "原因：车道线宽度不满足"
                        dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                        data_list = get_dict_list(dict)
                        dict_list.append(data_list)
                    if g_LCF_TJASA_Output_TJASTM_SysStateTJA_nu == 7:
                        level1 = "NNP退出"
                        level2 = "NNP异常退出"
                        level3 = "原因：PILOT关闭"
                        dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                        data_list = get_dict_list(dict)
                        dict_list.append(data_list)
                    if g_LCF_TJASA_Output_TJASTM_SysStateTJA_nu == 1 and (
                            g_LCFSEN_proDebugs_sTJASADebug_TJALKA_StrongReady_bool == 0 or g_LCFSEN_proDebugs_sTJASADebug_TJALKA_WeakReady_bool == 0):
                        SuppressReason_arr = get_binary_with_16(
                            g_LCFSEN_proDebugs_sTJASADebug_TJALKA_LaneCenterInvalid_btf)
                        # 根据每个位的值设置相应的变量
                        Bite0 = int(SuppressReason_arr[-1])
                        Bite1 = int(SuppressReason_arr[-2])
                        Bite2 = int(SuppressReason_arr[-3])
                        Bite3 = int(SuppressReason_arr[-4])
                        Bite4 = int(SuppressReason_arr[-5])
                        Bite5 = int(SuppressReason_arr[-6])
                        Bite6 = int(SuppressReason_arr[-7])
                        Bite7 = int(SuppressReason_arr[-8])
                        Bite8 = int(SuppressReason_arr[-9])
                        Bite9 = int(SuppressReason_arr[-10])
                        Bite10 = int(SuppressReason_arr[-11])
                        Bite11 = int(SuppressReason_arr[-12])
                        Bite12 = int(SuppressReason_arr[-13])
                        Bite13 = int(SuppressReason_arr[-14])
                        Bite14 = int(SuppressReason_arr[-15])
                        Bite15 = int(SuppressReason_arr[-16])

                        if Bite0:
                            level1 = "NNP退出"
                            level2 = "NNP异常退出"
                            level3 = "原因：车道线无效"
                            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                            data_list = get_dict_list(dict)
                            dict_list.append(data_list)
                        if Bite1:
                            level1 = "NNP退出"
                            level2 = "NNP异常退出"
                            level3 = "原因：超速"
                            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                            data_list = get_dict_list(dict)
                            dict_list.append(data_list)
                        if Bite2:
                            level1 = "NNP退出"
                            level2 = "NNP异常退出"
                            level3 = "原因：距离车道边界过近"
                            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                            data_list = get_dict_list(dict)
                            dict_list.append(data_list)

                        if Bite3:
                            level1 = "NNP退出"
                            level2 = "NNP异常退出"
                            level3 = "原因：车道宽度不满足"
                            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                            data_list = get_dict_list(dict)
                            dict_list.append(data_list)

                        if Bite4:
                            level1 = "NNP退出"
                            level2 = "NNP异常退出"
                            level3 = "原因：车道线曲率不满足"
                            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                            data_list = get_dict_list(dict)
                            dict_list.append(data_list)

                        if Bite5:
                            level1 = "NNP退出"
                            level2 = "NNP异常退出"
                            level3 = "原因：信号灯激活"
                            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                            data_list = get_dict_list(dict)
                            dict_list.append(data_list)
                        if Bite6:
                            level1 = "NNP退出"
                            level2 = "NNP异常退出"
                            level3 = "原因：检测到在施工现场(默认是不在的)"
                            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                            data_list = get_dict_list(dict)
                            dict_list.append(data_list)

                        if Bite7:
                            level1 = "NNP退出"
                            level2 = "NNP异常退出"
                            level3 = "原因：无法居中"
                            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                            data_list = get_dict_list(dict)
                            dict_list.append(data_list)

                        if Bite8:
                            level1 = "NNP退出"
                            level2 = "NNP异常退出"
                            level3 = "原因：strongready条件不满足"
                            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                            data_list = get_dict_list(dict)
                            dict_list.append(data_list)

                        if Bite9:
                            level1 = "NNP退出"
                            level2 = "NNP异常退出"
                            level3 = "原因：仅有跟车模式(这个模式已关闭)"
                            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                            data_list = get_dict_list(dict)
                            dict_list.append(data_list)

                        if Bite10:
                            level1 = "NNP退出"
                            level2 = "NNP异常退出"
                            level3 = "原因：检测到在变道"
                            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                            data_list = get_dict_list(dict)
                            dict_list.append(data_list)

                        if Bite11:
                            level1 = "NNP退出"
                            level2 = "NNP异常退出"
                            level3 = "原因：车道线长度不满足"
                            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                            data_list = get_dict_list(dict)
                            dict_list.append(data_list)

                        if Bite12:
                            level1 = "NNP退出"
                            level2 = "NNP异常退出"
                            level3 = "原因：车道线不在检测范围内"
                            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                            data_list = get_dict_list(dict)
                            dict_list.append(data_list)

                        if Bite13:
                            level1 = "NNP退出"
                            level2 = "NNP异常退出"
                            level3 = "原因：Blocking TimeOn（延迟时间较长）"
                            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                            data_list = get_dict_list(dict)
                            dict_list.append(data_list)

                        if Bite14:
                            level1 = "NNP退出"
                            level2 = "NNP异常退出"
                            level3 = "原因：主动取消"
                            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                            data_list = get_dict_list(dict)
                            dict_list.append(data_list)

                        if Bite15:
                            level1 = "NNP退出"
                            level2 = "NNP异常退出"
                            level3 = "原因：被动取消"
                            dict = get_dict(vechicle_id, start_time_str, bagid, path, scid_dict, level1, level2, level3)
                            data_list = get_dict_list(dict)
                            dict_list.append(data_list)

        #记录上一条数据
        ADCS12_NNP_State_Reminder_last=ADCS12_NNP_State_Reminder
        ADCS12_NNP_RINO_last=ADCS12_NNP_RINO
    add_to_bytehouse(dict_list)



